package com.example.bindservice;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.Nullable;

public class MyService extends Service {

    class MyBinder extends Binder {
        public void callMethodInService() {
            methodInService();
        }
    }

    public void methodInService() {
        Log.i("MyService", "执行服务中的 methodInService() 方法");
    }

    @Override
    public void onCreate() {
        Log.i("MyService", "创建服务, 执行 onCreate() 方法");
        super.onCreate();
    }

    public IBinder onBind (Intent intent) {
        Log.i("MyService", "绑定服务, 执行 onBind() 方法");
        return new MyBinder();
    }

    @Override
    public boolean onUnbind(Intent intent) {
        Log.i("MyService", "解绑服务, 执行 onUnbind() 方法");
        return super.onUnbind(intent);
    }
}
